import socket
import sys
from threading import Thread

name = sys.argv[1]

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(("10.2.0.243", 7777))
client.send("login:{}".format(name).encode("utf-8"))

def recv_message():
    while True:
        data = client.recv(65535).decode("utf-8")
        cmd, sender, message = data.split(":")
        if sender == "system":
            print("[ {} ]".format(message))
        else:
            print("{} said to me: {}".format(sender, message))


Thread(target=recv_message, daemon=True).start()

while True:
    message = input("Enter the message:(USER:MESSAGE) ")
    client.send("message:{}".format(message).encode("utf-8"))
